---
title: "appendix"
output: pdf_document
date: "2025-07-17"
---

# packages
```{r}
library(cobalt)
library(WeightIt)
library(interplot)
library(dplyr)
library(stargazer)
library(AER)
library(marginaleffects)
```

# load data
```{r}
load("data_democracy.rda")
```

# entropy balancing
```{r}
original <- bal.tab(final_monitor ~ domesticobs + first_multiparty +
                     executive + durable_lagged + Ln_GDP_lagged +
                     sanction + Ln_foreign_aid_lagged + 
                     v2x_polyarchy_lagged,
        data = dat_vdem33, estimand = "ATT", thresholds = c(m = .05))


wei <- weightit(final_monitor ~ domesticobs + executive + first_multiparty + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2x_polyarchy_lagged, data = dat_vdem33, estimand = "ATT", method = "ebal")
```

# Figure D.1
```{r}
mod_wei <- lm(sub_free_and_fair ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2x_polyarchy_lagged
            , dat_vdem33, weight = wei$weights)

df_eq <- interplot(m = mod_wei, var1 = "final_monitor", var2 = "domesticobs", ci = 0.95, plot = FALSE)

df_eq <- df_eq %>%
    mutate(
        domestic_label = factor(domesticobs, levels = c(0, 1), labels = c("Absence", "Presence")),
        sig_color = case_when(
            lb > 0 ~ ifelse(domesticobs == 0, "red", "blue"),
            ub < 0 ~ ifelse(domesticobs == 0, "red", "blue"),
            TRUE ~ "black"
        ),
        sig_shape = ifelse(domesticobs == 0, 17, 16)
    )

ggplot(df_eq, aes(x = coef, y = "Election Quality", group = domestic_label)) +
    geom_errorbarh(aes(xmin = lb, xmax = ub, color = sig_color),
                   position = position_dodge(width = 0.5), height = 0.15) +
    geom_point(aes(shape = domestic_label, color = sig_color),
               position = position_dodge(width = 0.5), size = 2.5) +
    geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
    scale_shape_manual(
        name = "Domestic Observer",
        values = c("Presence" = 16, "Absence" = 17),
        breaks = c("Presence", "Absence")
    ) +
    scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), guide = "none") +
    scale_x_continuous(
        limits = c(-0.3, 0.35),
        expand = expansion(mult = c(0, 0))
    ) +
    labs(x = NULL, y = NULL) +
    ggtitle("Marginal Effect of International Observer") +
    theme_classic() +
    theme(
        plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 12),
        legend.position = "bottom",
        legend.title = element_text(size = 12),
        legend.text = element_text(size = 11)
    )
```

# Figure D.2
```{r}
mod_weic <- lm(voterregistry ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2x_polyarchy_lagged
            , dat_vdem33, weight = wei$weights)

mod_weid <- lm(votebuy ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2x_polyarchy_lagged
            , dat_vdem33, weight = wei$weights)

mod_weif <- lm(govintimidat ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2x_polyarchy_lagged
            , dat_vdem33, weight = wei$weights)

mod_weig <- lm(nonstateviolence ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2x_polyarchy_lagged
            , dat_vdem33, weight = wei$weights)

df_c <- interplot(m = mod_weic, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Voter Registry")
df_d <- interplot(m = mod_weid, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Vote Buying")
df_f <- interplot(m = mod_weif, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Government Intimidation")
df_g <- interplot(m = mod_weig, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Non-state Electoral Violence")

df_combined <- bind_rows(df_c, df_d, df_f, df_g) %>%
  mutate(domestic_label = factor(domesticobs, levels = c(0, 1), labels = c("Absence", "Presence")),
    sig_color = case_when(
      lb > 0 ~ ifelse(domesticobs == 0, "red", "blue"),
      ub < 0 ~ ifelse(domesticobs == 0, "red", "blue"),
      TRUE ~ "black"
    ),
    sig_shape = ifelse(domesticobs == 0, 17, 16),  
    fraud_type = factor(fraud_type,
                        levels = c("Vote Buying", 
                                   "Voter Registry", 
                                   "Non-state Electoral Violence", 
                                   "Government Intimidation"))
  )


ggplot(df_combined, aes(x = coef, y = fraud_type, group = domestic_label)) +
  geom_errorbarh(aes(xmin = lb, xmax = ub, color = sig_color), 
                 position = position_dodge(width = 0.5), height = 0.15) +
  geom_point(aes(shape = domestic_label, color = sig_color), 
             position = position_dodge(width = 0.5), size = 2.5) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  scale_shape_manual(name = "Domestic Observer", 
                     values = c("Presence" = 16, "Absence" = 17),
    breaks = c("Presence", "Absence")) +
  scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), 
                     guide = "none") +
  scale_x_continuous(
    limits = c(-0.3, 0.55),
    expand = expansion(mult = c(0, 0))
  ) +
  labs(x = NULL, y = NULL) +
  ggtitle("Marginal Effect of International Observer") +
  theme_classic() +
  theme(
    plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
    axis.title.x = element_blank(),
    axis.text.y = element_text(size = 12),
    axis.title.x.bottom = element_blank(),
    legend.position = "bottom",
    legend.title = element_text(size = 12),
    legend.text = element_text(size = 11)
  )
```

# load data
```{r}
load("data_csorep.rda")
```

# entropy balancing
```{r}
original <- bal.tab(final_monitor ~ domesticobs + first_multiparty +
                     executive + durable_lagged + Ln_GDP_lagged +
                     sanction + Ln_foreign_aid_lagged + v2csreprss_lagged,
        data = dat_vdem44, estimand = "ATT", thresholds = c(m = .05))


wei <- weightit(final_monitor ~ domesticobs + executive + first_multiparty + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2csreprss_lagged, data = dat_vdem44, estimand = "ATT", method = "ebal")
```

# Figure D.3
```{r}
mod_wei <- lm(sub_free_and_fair ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2csreprss_lagged
            , dat_vdem44, weight = wei$weights)

df_eq <- interplot(m = mod_wei, var1 = "final_monitor", var2 = "domesticobs", ci = 0.95, plot = FALSE)

df_eq <- df_eq %>%
    mutate(
        domestic_label = factor(domesticobs, levels = c(0, 1), labels = c("Absence", "Presence")),
        sig_color = case_when(
            lb > 0 ~ ifelse(domesticobs == 0, "red", "blue"),
            ub < 0 ~ ifelse(domesticobs == 0, "red", "blue"),
            TRUE ~ "black"
        ),
        sig_shape = ifelse(domesticobs == 0, 17, 16)
    )

ggplot(df_eq, aes(x = coef, y = "Election Quality", group = domestic_label)) +
    geom_errorbarh(aes(xmin = lb, xmax = ub, color = sig_color),
                   position = position_dodge(width = 0.5), height = 0.15) +
    geom_point(aes(shape = domestic_label, color = sig_color),
               position = position_dodge(width = 0.5), size = 2.5) +
    geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
    scale_shape_manual(
        name = "Domestic Observer",
        values = c("Presence" = 16, "Absence" = 17),
        breaks = c("Presence", "Absence") 
    ) +
    scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), guide = "none") +
    scale_x_continuous(
        limits = c(-0.4, 0.3),
        expand = expansion(mult = c(0, 0))
    ) +
    labs(x = NULL, y = NULL) +
    ggtitle("Marginal Effect of International Observer") +
    theme_classic() +
    theme(
        plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 12),
        legend.position = "bottom",
        legend.title = element_text(size = 12),
        legend.text = element_text(size = 11)
    )
```

# Figure D.4
```{r}
mod_weic <- lm(voterregistry ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2csreprss_lagged
            , dat_vdem44, weight = wei$weights)

mod_weid <- lm(votebuy ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2csreprss_lagged
            , dat_vdem44, weight = wei$weights)

mod_weig <- lm(nonstateviolence ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged + v2csreprss_lagged
            , dat_vdem44, weight = wei$weights)

df_c <- interplot(m = mod_weic, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Voter Registry")
df_d <- interplot(m = mod_weid, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Vote Buying")
df_g <- interplot(m = mod_weig, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Non-state Electoral Violence")

df_combined <- bind_rows(df_c, df_d, df_g) %>% 
  mutate(
    domestic_label = factor(domesticobs, levels = c(0, 1), labels = c("Absence", "Presence")),
    sig_color = case_when(
      lb > 0 ~ ifelse(domesticobs == 0, "red", "blue"),
      ub < 0 ~ ifelse(domesticobs == 0, "red", "blue"),
      TRUE ~ "black"
    ),
    sig_shape = ifelse(domesticobs == 0, 17, 16),
    fraud_type = factor(fraud_type,
                        levels = c("Vote Buying", 
                                   "Voter Registry", 
                                   "Non-state Electoral Violence"))
  )

ggplot(df_combined, aes(x = coef, y = fraud_type, group = domestic_label)) +
  geom_errorbarh(aes(xmin = lb, xmax = ub, color = sig_color), 
                 position = position_dodge(width = 0.5), height = 0.15) +
  geom_point(aes(shape = domestic_label, color = sig_color), 
             position = position_dodge(width = 0.5), size = 2.5) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  scale_shape_manual(name = "Domestic Observer", 
                     values = c("Presence" = 16, "Absence" = 17),
    breaks = c("Presence", "Absence")) +
  scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), 
                     guide = "none") +
  scale_x_continuous(
    limits = c(-0.3, 0.55),
    expand = expansion(mult = c(0, 0))
  ) +
  labs(x = NULL, y = NULL) +
  ggtitle("Marginal Effect of International Observer") +
  theme_classic() +
  theme(
    plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
    axis.title.x = element_blank(),
    axis.text.y = element_text(size = 12),
    axis.title.x.bottom = element_blank(),
    legend.position = "bottom",
    legend.title = element_text(size = 12),
    legend.text = element_text(size = 11)
  )
```

# load data
```{r}
load("data_IV.rda")
```

# Table D.1
```{r}
first_stage <- lm(final_monitor ~ out + domesticobs + domesticobs*out + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged, data = dat_vdem_IV2)

stargazer(first_stage,
          omit.stat=c("ser", "bic", "ll", "adj.rsq"), 
          column.sep.width="1pt", font.size="small", digits=2, 
          dep.var.caption="Outcome variable")
```

# Figure D.5
```{r}
ivmod <- ivreg(formula = sub_free_and_fair ~ final_monitor + domesticobs + final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged | domesticobs + out + domesticobs*out + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged
            , data = dat_vdem_IV2)

iv_plotdata <- plot_slopes(ivmod, variables = "final_monitor", condition = "domesticobs", plot = FALSE)
iv_df <- iv_plotdata$data

iv_df <- iv_df %>%
  mutate(
    domestic_label = factor(domesticobs, levels = c(0, 1), labels = c("Absence", "Presence")),
    sig_color = case_when(
      conf.low > 0 ~ ifelse(domesticobs == 0, "red", "blue"),
      conf.high < 0 ~ ifelse(domesticobs == 0, "red", "blue"),
      TRUE ~ "black"
    ),
    sig_shape = ifelse(domesticobs == 0, 17, 16)
  )

ggplot(iv_df, aes(x = estimate, y = "Election Quality", group = domestic_label)) +
    geom_errorbarh(aes(xmin = conf.low, xmax = conf.high, color = sig_color),
                   position = position_dodge(width = 0.5), height = 0.15) +
    geom_point(aes(shape = domestic_label, color = sig_color),
               position = position_dodge(width = 0.5), size = 2.5) +
    geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
    scale_shape_manual(
        name = "Domestic Observer",
        values = c("Presence" = 16, "Absence" = 17),
        breaks = c("Presence", "Absence")
    ) +
    scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), guide = "none") +
    scale_x_continuous(
        limits = c(-0.5, 5),
        expand = expansion(mult = c(0, 0))
    ) +
    labs(x = NULL, y = NULL) +
    ggtitle("Marginal Effect of International Observer") +
    theme_classic() +
    theme(
        plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        legend.position = "bottom",
        legend.title = element_text(size = 12),
        legend.text = element_text(size = 11)
    )
```

# load data
```{r}
load("data_domobs_lagged.rda")
```

# entropy balancing
```{r}
dat_vdem55 <- na.omit(dat_vdem55)

original <- bal.tab(final_monitor ~ domesticobs_lagged + first_multiparty
                    + executive + durable_lagged + Ln_GDP_lagged
                    + sanction + Ln_foreign_aid_lagged,
        data = dat_vdem55, estimand = "ATT", thresholds = c(m = .05))


wei <- weightit(final_monitor ~ domesticobs_lagged + executive + first_multiparty + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged, data = dat_vdem55, estimand = "ATT", method = "ebal")
```

# Figure D.6
```{r}
mod21 <- lm(sub_free_and_fair ~ final_monitor*domesticobs_lagged + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem55
            , weight = wei$weights)

df_eq <- interplot(m = mod21, var1 = "final_monitor", var2 = "domesticobs_lagged", ci = 0.95, plot = FALSE)

df_eq <- df_eq %>%
    mutate(
        domestic_label = factor(domesticobs_lagged, levels = c(0, 1), labels = c("Absence", "Presence")),
        sig_color = case_when(
            lb > 0 ~ ifelse(domesticobs_lagged == 0, "red", "blue"),
            ub < 0 ~ ifelse(domesticobs_lagged == 0, "red", "blue"),
            TRUE ~ "black"
        ),
        sig_shape = ifelse(domesticobs_lagged == 0, 17, 16)
    )

ggplot(df_eq, aes(x = coef, y = "Election Quality", group = domestic_label)) +
    geom_errorbarh(aes(xmin = lb, xmax = ub, color = sig_color),
                   position = position_dodge(width = 0.5), height = 0.15) +
    geom_point(aes(shape = domestic_label, color = sig_color),
               position = position_dodge(width = 0.5), size = 2.5) +
    geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
    scale_shape_manual(
        name = "Domestic Observer",
        values = c("Presence" = 16, "Absence" = 17),
        breaks = c("Presence", "Absence") 
    ) +
    scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), guide = "none") +
    scale_x_continuous(
        limits = c(-0.25, 0.45),
        expand = expansion(mult = c(0, 0))
    ) +
    labs(x = NULL, y = NULL) +
    ggtitle("Marginal Effect of International Observer") +
    theme_classic() +
    theme(
        plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 12),
        legend.position = "bottom",
        legend.title = element_text(size = 12),
        legend.text = element_text(size = 11)
    )
```

# Figure D.7
```{r}
mod21c <- lm(voterregistry ~ final_monitor*domesticobs_lagged + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem55
            , weight = wei$weights)

mod21d <- lm(votebuy ~ final_monitor*domesticobs_lagged + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem55
            , weight = wei$weights)

mod21f <- lm(govintimidat ~ final_monitor*domesticobs_lagged + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem55
            , weight = wei$weights)

mod21g <- lm(nonstateviolence ~ final_monitor*domesticobs_lagged + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem55
            , weight = wei$weights)

df_c <- interplot(m = mod21c, var1 = "final_monitor", var2 = "domesticobs_lagged", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Voter Registry")
df_d <- interplot(m = mod21d, var1 = "final_monitor", var2 = "domesticobs_lagged", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Vote Buying")
df_f <- interplot(m = mod21f, var1 = "final_monitor", var2 = "domesticobs_lagged", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Government Intimidation")
df_g <- interplot(m = mod21g, var1 = "final_monitor", var2 = "domesticobs_lagged", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Non-state Electoral Violence")

df_combined <- bind_rows(df_c, df_d, df_f, df_g) %>%
  mutate(
    domestic_label = factor(domesticobs_lagged, levels = c(0, 1), labels = c("Absence", "Presence")),
    sig_color = case_when(
      lb > 0 ~ ifelse(domesticobs_lagged == 0, "red", "blue"),
      ub < 0 ~ ifelse(domesticobs_lagged == 0, "red", "blue"),
      TRUE ~ "black"
    ),
    sig_shape = ifelse(domesticobs_lagged == 0, 17, 16),  
    fraud_type = factor(fraud_type,
                        levels = c("Vote Buying", 
                                   "Voter Registry", 
                                   "Non-state Electoral Violence", 
                                   "Government Intimidation"))
  )

ggplot(df_combined, aes(x = coef, y = fraud_type, group = domestic_label)) +
  geom_errorbarh(aes(xmin = lb, xmax = ub, color = sig_color), 
                 position = position_dodge(width = 0.5), height = 0.15) +
  geom_point(aes(shape = domestic_label, color = sig_color), 
             position = position_dodge(width = 0.5), size = 2.5) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  scale_shape_manual(name = "Domestic Observer", 
                     values = c("Presence" = 16, "Absence" = 17),
    breaks = c("Presence", "Absence")) +
  scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), 
                     guide = "none") +
  scale_x_continuous(
    limits = c(-0.35, 0.4),
    expand = expansion(mult = c(0, 0))
  ) +
  labs(x = NULL, y = NULL) +
  ggtitle("Marginal Effect of International Observer") +
  theme_classic() +
  theme(
    plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
    axis.title.x = element_blank(),
    axis.text.y = element_text(size = 12),
    axis.title.x.bottom = element_blank(),
    legend.position = "bottom",
    legend.title = element_text(size = 12),
    legend.text = element_text(size = 11)
  )
```

# load data
```{r}
load("data_exc.rda")
```

# entropy balancing
```{r}
original <- bal.tab(final_monitor ~ domesticobs + first_multiparty
                    + executive + durable_lagged + Ln_GDP_lagged
                    + sanction + Ln_foreign_aid_lagged,
        data = dat_vdem66, estimand = "ATT", thresholds = c(m = .05))


wei <- weightit(final_monitor ~ domesticobs + executive + first_multiparty + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged, data = dat_vdem66, estimand = "ATT", method = "ebal")
```

# Figure D.8
```{r}
mod_wei <- lm(sub_free_and_fair ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem66, weight = wei$weights)

df_eq <- interplot(m = mod_wei, var1 = "final_monitor", var2 = "domesticobs", ci = 0.95, plot = FALSE)

df_eq <- df_eq %>%
    mutate(
        domestic_label = factor(domesticobs, levels = c(0, 1), labels = c("Absence", "Presence")),
        sig_color = case_when(
            lb > 0 ~ ifelse(domesticobs == 0, "red", "blue"),
            ub < 0 ~ ifelse(domesticobs == 0, "red", "blue"),
            TRUE ~ "black"
        ),
        sig_shape = ifelse(domesticobs == 0, 17, 16)
    )

ggplot(df_eq, aes(x = coef, y = "Election Quality", group = domestic_label)) +
    geom_errorbarh(aes(xmin = lb, xmax = ub, color = sig_color),
                   position = position_dodge(width = 0.5), height = 0.15) +
    geom_point(aes(shape = domestic_label, color = sig_color),
               position = position_dodge(width = 0.5), size = 2.5) +
    geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
    scale_shape_manual(
        name = "Domestic Observer",
        values = c("Presence" = 16, "Absence" = 17),
        breaks = c("Presence", "Absence")
    ) +
    scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), guide = "none") +
    scale_x_continuous(
        limits = c(-0.45, 0.3),
        expand = expansion(mult = c(0, 0))
    ) +
    labs(x = NULL, y = NULL) +
    ggtitle("Marginal Effect of International Observer") +
    theme_classic() +
    theme(
        plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 12),
        legend.position = "bottom",
        legend.title = element_text(size = 12),
        legend.text = element_text(size = 11)
    )
```

# Figure D.9
```{r}
mod_weic <- lm(voterregistry ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem66, weight = wei$weights)

mod_weid <- lm(votebuy ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem66, weight = wei$weights)

mod_weif <- lm(govintimidat ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem66, weight = wei$weights)

mod_weig <- lm(nonstateviolence ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem66, weight = wei$weights)

df_c <- interplot(m = mod_weic, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Voter Registry")
df_d <- interplot(m = mod_weid, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Vote Buying")
df_f <- interplot(m = mod_weif, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Government Intimidation")
df_g <- interplot(m = mod_weig, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Non-state Electoral Violence")

df_combined <- bind_rows(df_c, df_d, df_f, df_g) %>%
  mutate(
    domestic_label = factor(domesticobs, levels = c(0, 1), labels = c("Absence", "Presence")),
    sig_color = case_when(
      lb > 0 ~ ifelse(domesticobs == 0, "red", "blue"),
      ub < 0 ~ ifelse(domesticobs == 0, "red", "blue"),
      TRUE ~ "black" 
    ),
    sig_shape = ifelse(domesticobs == 0, 17, 16),
    fraud_type = factor(fraud_type,
                        levels = c("Vote Buying", 
                                   "Voter Registry", 
                                   "Non-state Electoral Violence", 
                                   "Government Intimidation"))
  )


ggplot(df_combined, aes(x = coef, y = fraud_type, group = domestic_label)) +
  geom_errorbarh(aes(xmin = lb, xmax = ub, color = sig_color), 
                 position = position_dodge(width = 0.5), height = 0.15) +
  geom_point(aes(shape = domestic_label, color = sig_color), 
             position = position_dodge(width = 0.5), size = 2.5) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  scale_shape_manual(name = "Domestic Observer", 
                     values = c("Presence" = 16, "Absence" = 17),
    breaks = c("Presence", "Absence")) +
  scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), 
                     guide = "none") +
  scale_x_continuous(
    limits = c(-0.3, 0.55),
    expand = expansion(mult = c(0, 0))
  ) +
  labs(x = NULL, y = NULL) +
  ggtitle("Marginal Effect of International Observer") +
  theme_classic() +
  theme(
    plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
    axis.title.x = element_blank(),
    axis.text.y = element_text(size = 12),
    axis.title.x.bottom = element_blank(),
    legend.position = "bottom",
    legend.title = element_text(size = 12),
    legend.text = element_text(size = 11)
  )
```

# load data
```{r}
load("data.rda")
```

# Table D.2
```{r}
mod_wei0 <- lm(sub_free_and_fair ~ final_monitor + domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem2)

mod_wei <- lm(sub_free_and_fair ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem2)

mod_weic <- lm(voterregistry ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem2)

mod_weid <- lm(votebuy ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem2)

mod_weif <- lm(govintimidat ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem2)

mod_weig <- lm(nonstateviolence ~ final_monitor*domesticobs + first_multiparty + executive + factor(country) + durable_lagged + Ln_GDP_lagged + sanction + Ln_foreign_aid_lagged 
            , dat_vdem2)

stargazer(mod_wei0, mod_wei, mod_weif, mod_weig, mod_weic, mod_weid,
          omit.stat=c("f", "ser", "bic", "ll", "adj.rsq"), 
          column.sep.width="1pt", font.size="small", digits=2, 
          dep.var.caption="Outcome variable")
```

# Figure D.10
```{r}
df_eq <- interplot(m = mod_wei, var1 = "final_monitor", var2 = "domesticobs", ci = 0.95, plot = FALSE)

df_eq <- df_eq %>%
    mutate(
        domestic_label = factor(domesticobs, levels = c(0, 1), labels = c("Absence", "Presence")),
        sig_color = case_when(
            lb > 0 ~ ifelse(domesticobs == 0, "red", "blue"),
            ub < 0 ~ ifelse(domesticobs == 0, "red", "blue"),
            TRUE ~ "black"
        ),
        sig_shape = ifelse(domesticobs == 0, 17, 16)
    )

ggplot(df_eq, aes(x = coef, y = "Election Quality", group = domestic_label)) +
    geom_errorbarh(aes(xmin = lb, xmax = ub, color = sig_color),
                   position = position_dodge(width = 0.5), height = 0.15) +
    geom_point(aes(shape = domestic_label, color = sig_color),
               position = position_dodge(width = 0.5), size = 2.5) +
    geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
    scale_shape_manual(
        name = "Domestic Observer",
        values = c("Presence" = 16, "Absence" = 17),
        breaks = c("Presence", "Absence")
    ) +
    scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), guide = "none") +
    scale_x_continuous(
        limits = c(-0.3, 0.35),
        expand = expansion(mult = c(0, 0))
    ) +
    labs(x = NULL, y = NULL) +
    ggtitle("Marginal Effect of International Observer") +
    theme_classic() +
    theme(
        plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 12),
        legend.position = "bottom",
        legend.title = element_text(size = 12),
        legend.text = element_text(size = 11)
    )
```

# Figure D.11
```{r}
df_c <- interplot(m = mod_weic, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Voter Registry")
df_d <- interplot(m = mod_weid, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Vote Buying")
df_f <- interplot(m = mod_weif, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Government Intimidation")
df_g <- interplot(m = mod_weig, var1 = "final_monitor", var2 = "domesticobs", ci = .95, plot = FALSE) %>%
  mutate(fraud_type = "Non-state Electoral Violence")

df_combined <- bind_rows(df_c, df_d, df_f, df_g) %>%
  mutate(
    domestic_label = factor(domesticobs, levels = c(0, 1), labels = c("Absence", "Presence")),
    sig_color = case_when(
      lb > 0 ~ ifelse(domesticobs == 0, "red", "blue"),
      ub < 0 ~ ifelse(domesticobs == 0, "red", "blue"),
      TRUE ~ "black"
    ),
    sig_shape = ifelse(domesticobs == 0, 17, 16),  
    fraud_type = factor(fraud_type,
                        levels = c("Vote Buying", 
                                   "Voter Registry", 
                                   "Non-state Electoral Violence", 
                                   "Government Intimidation"))
  )

ggplot(df_combined, aes(x = coef, y = fraud_type, group = domestic_label)) +
  geom_errorbarh(aes(xmin = lb, xmax = ub, color = sig_color), 
                 position = position_dodge(width = 0.5), height = 0.15) +
  geom_point(aes(shape = domestic_label, color = sig_color), 
             position = position_dodge(width = 0.5), size = 2.5) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  scale_shape_manual(name = "Domestic Observer", 
                     values = c("Presence" = 16, "Absence" = 17),
    breaks = c("Presence", "Absence")) +
  scale_color_manual(values = c("black" = "black", "red" = "red", "blue" = "blue"), 
                     guide = "none") +
  scale_x_continuous(
    limits = c(-0.3, 0.55),
    expand = expansion(mult = c(0, 0))
  ) +
  labs(x = NULL, y = NULL) +
  ggtitle("Marginal Effect of International Observer") +
  theme_classic() +
  theme(
    plot.title = element_text(hjust = 0.5, size = 13, margin = margin(b = 10)),
    axis.title.x = element_blank(),
    axis.text.y = element_text(size = 12),
    axis.title.x.bottom = element_blank(),
    legend.position = "bottom",
    legend.title = element_text(size = 12),
    legend.text = element_text(size = 11)
  )
```